package couk.mmtdigital.sm.view
{
	import couk.mmtdigital.sm.ApplicationFacade;
	import couk.mmtdigital.sm.model.vo.LoginVO;
	import couk.mmtdigital.sm.view.components.LoginView;
	
	import flash.events.MouseEvent;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;

	public class LoginViewMediator extends Mediator implements IMediator
	{
		public static const NAME:String = "LoginViewMediator";
		
		public function LoginViewMediator(vc:Object=null)
		{
			super(NAME, vc);
			loginView.loginBtn.addEventListener(MouseEvent.CLICK, onLoginClick);
		}
		
		private function onLoginClick(evt:MouseEvent):void{
			sendNotification(ApplicationFacade.LOGIN, new LoginVO(loginView.userInput.text, loginView.passInput.text));
		}
		
		private function resetLoginFrm():void{
			loginView.userInput.text = "";
			loginView.passInput.text = "";
		}
		
		override public function listNotificationInterests():Array{
			return [
				ApplicationFacade.LOGGED	
			];
		}
		
		override public function handleNotification(notification:INotification):void{
			switch(notification.getName()){
				case ApplicationFacade.LOGGED:
					resetLoginFrm();
			}
		}
		
		private function get loginView():LoginView{
			return viewComponent as LoginView;
		}
	}
}